/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mop.dinnerbook.servlet;

import com.mop.dinnerbook.dao.BaseDAO;
import com.mop.dinnerbook.dao.ProjectDAO;

import java.io.*;
import java.net.*;

import java.util.List;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 *起转发作用的servlet
 * 读取web.xml配置文件，取出数据库配置文件的路径和导出文件的路径
 * @author qianwp
 */
public class DinnerServlet extends HttpServlet {
   
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    @Override
    public void init(ServletConfig config) throws ServletException{
        String configPath = config.getInitParameter("dbconfig");
        BaseDAO.config = config.getServletContext().getRealPath(configPath);
        System.out.println("-------------"+configPath+"----------------");
    }
    
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException{
        RequestDispatcher dispatcher = request.getRequestDispatcher("/main.jsp");
        ProjectDAO dao = new ProjectDAO();
        List result = dao.getAllProject();
        request.setAttribute("proList", result);
        dispatcher.forward(request, response);
    }
    
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException{
        doGet(request,response);
    }
}
